/*
 * @Author: muuzi@163.com muuzi@163.com
 * @Date: 2024-12-04 22:55:50
 * @LastEditors: muuzi@163.com muuzi@163.com
 * @LastEditTime: 2024-12-15 22:22:42
 * @FilePath: /mp-wechat/mock/user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// mock/user.ts

import { resultSuccess } from "../_util"

const createUserList = () => {
    return [
        {
            userId: 1,
            avatar: 'https://pic1.zhimg.com/80/v2-083faf550543c1e9f134b56b3322ee3c_720w.webp',
            username: 'admin',
            password: '123456789',
            desc: '下船不谈船里事',
            roles: ['平台管理员'],
            buttons: ['cuser.detail'],
            routes: ['home'],
            token: 'Admin Token',
            nickname: 'wendy'
        },
        {
            userId: 2,
            avatar: 'https://pic1.zhimg.com/80/v2-e1427f6a21122ac163ff98d24f55d372_720w.webp',
            username: 'system',
            password: '123456789',
            desc: '旧人不谈近况，新人不讲过往',
            roles: ['系统管理员'],
            buttons: ['cuser.detail', 'cuser.user'],
            routes: ['home'],
            token: 'Admin Token',
             nickname: 'wendy2',
        }
    ]
}
export default [

    // 获取用户信息接口
    {
        url: '/user/info',
        method: 'get',
        response: (request: any) => {
           
            // 获取请求头携带的 token
            const token = request.headers.authorization
            console.log('token=====',token)
            // 查看用户信息数据中是否包含有此 token 的用户
            const checkUser = createUserList().find((item) => "Bearer " + item.token === token)
            // 没有就返回失败信息
            if (!checkUser) {
                return {
                    code: 201,
                    data: {
                        msg: '获取用户信息失败'
                    }
                }
            }
            // 有就返回成功信息
            return resultSuccess(checkUser)
            // return {
            //     code: 200,
            //     data: {
            //         checkUser
            //     }
            // }
        }
    }
]
